package cn.caplike.demo.rabbitmq.api.exchange.direct;

import cn.caplike.demo.rabbitmq.api.Application;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author LiKe
 * @version 1.0.0
 * @date 2020-02-18 14:43
 */
public class Producer4DirectExchange {

    public static void main(String[] args) throws IOException, TimeoutException {
        // 创建一个链接工厂
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost(Application.RABBITMQ_HOST);
        connectionFactory.setPort(Application.RABBITMQ_PORT);
        connectionFactory.setVirtualHost("/");

        // 通过链接工厂创建连接
        Connection connection = connectionFactory.newConnection();

        // 通过连接创建一个 Channel
        Channel channel = connection.createChannel();
        channel.basicPublish("test_direct_exchange", "test.direct", null, "Hello RabbitMQ 4 Direct Exchange Message ...".getBytes());

        // 关闭连接
        channel.close();
        connection.close();
    }

}
